﻿using UnityEngine;
using UnityEngine.UI;

[DisallowMultipleComponent]
public class UILangItem : MonoBehaviour
{
    public delegate string GetLangFunc(string key);
    public static GetLangFunc onGetLang;

    public string key;

    void Awake()
    {
        SetText();
    }

    public void SetText()
    {
        if (onGetLang != null && !string.IsNullOrEmpty(key))
        {
            string text = onGetLang(key);
            if (!string.IsNullOrEmpty(text))
            {
                Text item = gameObject.GetComponent<Text>();
                if (item != null)
                {
                    item.text = text;
                }
            }
        }
    }
}
